package com.example.campus.controller.user;

import com.example.campus.pojo.dto.InfoPageQueryDTO;
import com.example.campus.pojo.dto.InfoPublishDTO;
import com.example.campus.pojo.dto.InfoUpdateDTO;
import com.example.campus.pojo.vo.LostAndFoundInfoDetailVO;
import com.example.campus.result.PageResult;
import com.example.campus.result.Result;
import com.example.campus.service.LostAndFoundInfoService;
import com.example.campus.utils.constant.MessageConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController("userLostAndFoundInfoController")
@RequestMapping("/user/lostAndFound")
@Slf4j
@Api(tags = "用户端失物拾物相关接口")
public class LostAndFoundInfoController {
    @Autowired
    private LostAndFoundInfoService lostAndFoundInfoService;

    @PostMapping("/publish")
    @ApiOperation("用户发布失物或寻物信息")
    public Result publish(@RequestBody @Validated InfoPublishDTO infoPublishDTO) {
        lostAndFoundInfoService.publish(infoPublishDTO);
        return Result.success(MessageConstant.PUBLISH_SUCCESS);
    }

    @PutMapping("/update")
    @ApiOperation("用户更新自己发布的失物或寻物信息")
    public Result update(@RequestBody @Validated InfoUpdateDTO infoUpdateDTO) {
        lostAndFoundInfoService.update(infoUpdateDTO);
        return Result.success(MessageConstant.UPDATE_SUCCESS);
    }

    @GetMapping("/detail/{id}")
    @ApiOperation("根据ID获取失物或寻物详细信息")
    public Result<LostAndFoundInfoDetailVO> getDetail(@PathVariable("id") Long id) {
        LostAndFoundInfoDetailVO lostAndFoundInfoDetailVO = lostAndFoundInfoService.getDetail(id);
        return Result.success(lostAndFoundInfoDetailVO);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("根据ID删除失物拾物信息")
    public Result delete(@PathVariable("id") Long id) {
        lostAndFoundInfoService.delete(id);
        return Result.success(MessageConstant.DELETE_SUCCESS);
    }

    @GetMapping("/list")
    @ApiOperation("失物/寻物信息分页查询")
    public Result<PageResult> lostAndFoundInfoList(InfoPageQueryDTO infoPageQueryDTO) {
        PageResult pageResult = lostAndFoundInfoService.getInfoList(infoPageQueryDTO);
        return Result.success(pageResult, MessageConstant.GET_LIST_SUCCESS);
    }

    @PutMapping("/status/{id}")
    @ApiOperation("用户修改发布的失物/拾物信息状态")
    public Result updateStatus(@PathVariable("id") Long id) {
        lostAndFoundInfoService.updateStatus(id);
        return Result.success(MessageConstant.UPDATE_SUCCESS);
    }
}
